package com.crm.service.impl.customerManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.SingleProductCustomerCustomMapper;
import com.crm.dao.mapper.customerManager.SingleProductCustomerMapper;
import com.crm.model.entity.customerManager.SingleProductCustomer;
import com.crm.model.entity.customerManager.SingleProductCustomerExample;
import com.crm.model.qo.customerManager.SingleProductCustomerQO;
import com.crm.model.vo.customerManager.SingleProductCustomerVO;
import com.crm.service.customerManager.SingleProductCustomerDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/4/29 15:31
 */
@Service
public class SingleProductCustomerDbServiceImpl implements SingleProductCustomerDbService {
    @Autowired
    private SingleProductCustomerCustomMapper singleProductCustomerCustomMapper;

    @Autowired
    private SingleProductCustomerMapper singleProductCustomerMapper;

    /**
     * 客户管理-单品客户-超级管理员
     * @Author pym
     * @Date  2021/4/29 15:32
     * @param singleProductCustomerQO -查询条件
     * @param dateUnit -日期类型(全部/本周/本月/本年度)
     * @param sortOrder -排序列
     * @return {@link {java.util.List<com.crm.model.vo.customerManager.SingleProductCustomerVO>}}
     */
    @Override
    public List<SingleProductCustomerVO> selectAllSingleProductCustomerList(SingleProductCustomerQO singleProductCustomerQO, Integer dateUnit, String sortOrder) {
        return singleProductCustomerCustomMapper.selectAllSingleProductCustomerList(singleProductCustomerQO, dateUnit, sortOrder);
    }

    /**
     * 客户管理-单品客户
     * @Author pym
     * @Date  2021/4/29 15:43
     * @param singleProductCustomerQO -查询条件
     * @param dateUnit -日期类型(全部/本周/本月/本年度)
     * @param sortOrder -排序列
     * @param accountId -账号ID
     * @return {@link {java.util.List<com.crm.model.vo.customerManager.SingleProductCustomerVO>}}
     */
    @Override
    public List<SingleProductCustomerVO> selectNormalSingleProductCustomerList(SingleProductCustomerQO singleProductCustomerQO, Integer dateUnit, String sortOrder, String accountId) {
        return singleProductCustomerCustomMapper.selectNormalSingleProductCustomerList(singleProductCustomerQO, dateUnit, sortOrder, accountId);
    }

    /**
     * 判断单品客户是否重复
     * @Author pym
     * @Date  2021/4/30 11:41
     * @param customerId 客户ID
     * @return {@link {java.lang.Boolean}}
     */
    @Override
    public Boolean isSingleProductCustomerRepeat(String customerId, String accountId) {
        Boolean result = false;
        SingleProductCustomerExample singleProductCustomerExample = new SingleProductCustomerExample();
        SingleProductCustomerExample.Criteria criteria = singleProductCustomerExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andCreatePeopleIdEqualTo(accountId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<SingleProductCustomer> singleProductCustomerList = singleProductCustomerMapper.selectByExample(singleProductCustomerExample);
        if (singleProductCustomerList.size() > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 新增单品客户
     * @Author pym
     * @Date  2021/4/30 11:51
     * @param singleProductCustomer 单品客户
     * @return {@link {java.lang.Boolean}}
     */
    @Override
    public Boolean insertSingleProductCustomer(SingleProductCustomer singleProductCustomer) {
        Boolean result = false;
        int num = singleProductCustomerMapper.insertSelective(singleProductCustomer);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 根据主键修改单品客户
     * @Author pym
     * @Date  2021/7/15 10:08
     * @param singleProductCustomer 单品客户
     * @return {@link {java.lang.Boolean}}
     */
    @Override
    public Boolean updateSingleProductCustomerById(SingleProductCustomer singleProductCustomer) {
        Boolean result = false;
        int num = singleProductCustomerMapper.updateByPrimaryKeySelective(singleProductCustomer);
        if (num > 0) {
            result = true;
        }
        return result;
    }
}
